<?php

namespace IDock\Insurance\ZMBX\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\ZMBX\ZMBXEnums;
use IDock\Insurance\ZMBX\Response\AllZMBXResponse;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleModelResponse extends AllZMBXResponse
{

    /**
     * @var VehicleModelPrinter $printer
     */
    public $printer = VehicleModelPrinter::class;

    public function printerInit(): Response
    {
        $modelList = $this->getBody()['simpleStadarCar'] ?? [];

        if (!$modelList) {
            return $this;
        }

        foreach ($modelList as $datum) {

            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->vehicleModelCode = $datum['localModelCode'] ?? '';
            $vehiclePrinter->brandName = $datum['brand'] ?? '';
            $vehiclePrinter->vehicleExhaust = $datum['displacement'] ?? '';
            $vehiclePrinter->familyName = $datum['series'] ?? '';
            $vehiclePrinter->power = $datum['power'] ?? '';

            $vehiclePrinter->vehicleName = $datum['brand'] ?? '';
            $vehiclePrinter->vehiclePrice = $datum['purchasePrice'] ?? '';
            $vehiclePrinter->vehiclePriceTax = $datum['purchasePrice'] ?? '';
            $vehiclePrinter->vehicleSeat = $datum['approvedPassengersCapacity'] ?? '';
            $vehiclePrinter->remark = $datum['modelDesc'] ?? '';

            $vehiclePrinter->vehicleYear = $datum['lfDate'] ?? '';

            $tonCount = $datum['approvedLoad'] ?? '0';
            if (!$tonCount) {
                $tonCount = '0';
            }else{
                $tonCount = $tonCount * 1000;
            }

            $vehiclePrinter->vehicleTonnage = $tonCount;
            $vehiclePrinter->wholeWeight = $datum['unladenMass'] ?? '';
            //能源类型
            $powerTypeCode = $datum['energyTypes'] ?? '0';
            $vehiclePrinter->energyTypeCode = array_search($powerTypeCode,ZMBXEnums::$energyType);
            $vehiclePrinter->energyTypeName = IDockEnums::$energyType[$vehiclePrinter->energyTypeCode] ?? '';

            if ($powerTypeCode == '1' or $powerTypeCode == '3') {
                $vehiclePrinter->isNewEnergy = '1';
            }
            $vehiclePrinter->item = $datum;
            $this->printer->setModelList($vehiclePrinter);
        }

        return $this;
    }
}
